package com.ego.common.constant;

/**
 * @program: ego
 * @description: 订单常量及枚举
 * @author: KamTang
 * @create: 2022-12-22 16:58
 **/
public class OrderConstant {
    /**
     * 订单令牌前缀
     */
    public static final String ORDER_TOKEN_PREFIX = "order:token:";

    /**
     * 订单验价时可接受的价格差
     */
    public static final Double ORDER_IGNORE_PRICE_DIFFERENCE = 0.01;

    /**
     * 订单状态
     */
    public enum StatusEnum {
        /**
         * 待付款
         * 已付款
         * 已发货
         * 已完成
         * 已关闭
         * 售后中
         * 售后完成
         */
        CREATE_NEW(0,"待付款"),
        PAYED(1,"已付款"),
        DELIVERED(2,"已发货"),
        FINISHED(3,"已完成"),
        CLOSED(4,"已关闭"),
        SERVICING(5,"售后中"),
        SERVICED(6,"售后完成");
        private final int code;
        private final String msg;

        StatusEnum(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public static StatusEnum getByCode(int code) {
            for (StatusEnum e : StatusEnum.values()) {
                if (e.getCode() == code) {
                    return e;
                }
            }
            return null;
        }

        public String getMsg() {
            return msg;
        }
    }

    /**
     * 交易状态枚举
     */
    public enum TransactionStatusEnum {
        /**
         * 交易创建，等待买家付款
         * 未付款交易超时关闭，或支付完成后全额退款
         * 交易支付成功
         * 交易结束，不可退款
         */
        WAIT_BUYER_PAY("交易创建，等待买家付款"),
        TRADE_CLOSED("未付款交易超时关闭，或支付完成后全额退款"),
        TRADE_SUCCESS("交易支付成功"),
        TRADE_FINISHED("交易结束，不可退款");
        private final String msg;

        TransactionStatusEnum(String msg) {
            this.msg = msg;
        }

        public String getMsg() {
            return msg;
        }
    }

    /**
     * 订单来源
     */
    public enum SourceType {
        /**
         * PC端
         * APP端
         */
        PC(0),
        APP(1);
        private final int code;

        SourceType(int code) {
            this.code = code;
        }

        public int getType() {
            return code;
        }
    }

    /**
     * 订单支付类型
     */
    public enum PayType {
        /**
         * 支付宝
         * 微信
         */
        ZFB(0, "支付宝"),
        WECHAT(1, "微信");
        private final int code;
        private final String msg;

        PayType(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public int getType() {
            return code;
        }

        public String getMsg() {
            return msg;
        }
    }
}
